package kr.hkit.androidcomplete02.ch01;

import java.security.Principal;
import java.security.acl.Group;
import java.util.Enumeration;

import kr.hkit.androidcomplete02.R;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.Toast;

public class GalleryTest extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.gallery_test);

		GridView grid = (GridView) findViewById(R.id.grid);
		ImageAdapter Adapter = new ImageAdapter(this);
		grid.setAdapter(Adapter);

		grid.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				Toast.makeText(GalleryTest.this, position + "번째 그림 선택",
						Toast.LENGTH_SHORT).show();

			}

		});
	}

	class ImageAdapter extends BaseAdapter {
		private Context mContext;

		int[] picture = { R.drawable.babydrum1, R.drawable.babydrum2,
				R.drawable.babydrum3, R.drawable.btnexit,
				R.drawable.flower_nodpi };
		
		public ImageAdapter(Context c){
			mContext = c;
		}
		
		@Override
		public int getCount() {
			return 100;
		}

		@Override
		public Object getItem(int position) {
			return picture[position % 5];
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ImageView imageView;
			if(convertView == null){
				imageView = new ImageView(mContext);
				imageView.setLayoutParams(new GridView.LayoutParams(80,60));
				imageView.setAdjustViewBounds(false);
				
			}
			return null;
		}
	}

}
